package com.fortressweb.servlet;

import java.io.IOException;



import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.demoweb.model.dao.MembershipDao;
import com.demoweb.model.dto.Membership;

@WebServlet("/fortress/fortressRegister.nhn")
public class FortressRegisterServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		resp.setContentType("text/html; charset=utf-8");
		
		String memberId = req.getParameter("memberId");
		String passwd = req.getParameter("passwd");
		String email = req.getParameter("email");
		String address = req.getParameter("address");
		String regNum = req.getParameter("regNum");
		String name = req.getParameter("name");
		
		System.out.println(memberId);
		System.out.println(passwd);
		System.out.println(email);
		System.out.println(address);
		System.out.println(regNum);
		
		Membership member = new Membership();
		member.setMemberId(memberId);
		member.setPassword(passwd);
		member.setEmail(email);
		member.setAddress(address);
		member.setRegistraionNumber(regNum);
		member.setName(name);
		
		MembershipDao dao = new MembershipDao();
		dao.insertMember(member);
	
		// 등록 후 목록 화면으로 이동
		// HTTttpResponse.sendRedirect: 지정된 경로로 요청을 재전송
		resp.sendRedirect("fortressMain.nhn");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		doGet(req, resp);
	}
}
